package com.xiaobias.day004;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;

import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.NotBlank;

/**
 * 创建request实体类.
 *
 * @author <a href="mailto:197772517@qq.com">longw.dr</a>
 * @date 2023-11-10 15-23
 * @since 1.0
 */
@Data
@NoArgsConstructor
public class TestRequest {
    @NotBlank(message = "name不能为空")
    private String name;
    @Length(max = 3, message =  "address最大长度为3")
    private String address;
    @Max(value = 5, message = "reqNo最大值是5")
    private String reqNo;

    // 嵌套必须加 @Valid，如果只在字段上添加校验注解嵌套中的验证不生效。
    @Valid
    private TestRequestInner inner;

    @Data
    @NoArgsConstructor
    public static class TestRequestInner {
        @Length(max = 3, message = "最大长度为3")
        private String sonName;
        private Integer sonAge;
        private String schoolNo;
    }
}
